<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
        <title>AJ Utils-ObjectHelper Tutorial</title>
        <meta name="description" content="Small Java utilities with many useful functions. Provides utility methods for working with Java objects" />
        <meta name="keywords" content="AJ Utils, ajaxjs, ajaxjs framework, java utilities, tools, helper, object,utilities,cloning" />
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <link rel="stylesheet" href="https://framework.ajaxjs.com/static/new-ui/css/common.css" />
        <link rel="stylesheet" href="https://iam.ajaxjs.com/asset/main.css"/>
        <link rel="icon" type="image/x-icon" href="https://framework.ajaxjs.com/aj-logo/logo.ico"/>
        <script src="https://framework.ajaxjs.com/static/aj-docs/common.js"></script>
        <script>
            // 获取用户的默认语言
            var userLang = navigator.language || navigator.userLanguage;

            // 检查是否为中文环境（包括简体和繁体）
            if (userLang.startsWith('zh') && location.pathname.indexOf('cn') == -1) {
                 confirm('欢迎！您可以改为访问中文内容。是否继续？') && location.assign('/cn');  // 如果是中文，则弹出提示
            }

            var _hmt = _hmt || [];
            (function() {
              var hm = document.createElement("script");
              hm.src = "https://hm.baidu.com/hm.js?208c5aea11c52991bd1c3283e62ad0ce";
              var s = document.getElementsByTagName("script")[0];
              s.parentNode.insertBefore(hm, s);
            })();
        </script>
    </head>
    <body>
        <nav>
            <div>
                <div class="links">
                    <a href="/">🏠 Home</a>
                    | ⚙️ Source:
                    <a target="_blank" href="https://github.com/lightweight-component/aj-util">Github</a>/<a target="_blank" href="https://gitcode.com/lightweight-component/aj-util">Gitcode</a>
                    | 🚀 <a href="/cn">Chinese Version</a>
                </div>
                <h1>
                    <img src="https://framework.ajaxjs.com/aj-logo/logo.png" style="vertical-align: middle;height: 45px;margin-bottom: 6px;" />
                    AJ Utils
                </h1>
                <h3>Small Java Utils Library</h3>
            </div>
        </nav>
        <div>
            <menu>
                
                <ul>
                    <li class="selected">
                        <a href="/">Home</a>
                    </li>
                </ul>
                <h3>Common</h3>
                <ul>
                    <li><a href="/common/JsonUtil/">JsonUtil</a></li>
                    <li><a href="/common/BytesHelper/">BytesHelper</a></li>
                    <li><a href="/common/ConvertBasicValue/">ConvertBasicValue</a></li>
                    <li><a href="/common/MessageDigestHelper/">HashHelper</a></li>
                    <li><a href="/common/MapTool/">MapTool</a></li>
                    <li><a href="/common/ObjectHelper/">ObjectHelper</a></li>
                    <li><a href="/common/RandomTools/">RandomTools</a></li>
                    <li><a href="/common/RegExpUtils/">RegExpUtils</a></li>
                    <li><a href="/common/StrUtil/">StrUtil</a></li>
                    <li><a href="/common/BoxLogger/">BoxLogger</a></li>
                    <li><a href="/common/BytesHelper/">BytesHelper</a></li>
                    <li><a href="/common/EncodeTools/">UrlEncode</a></li>
                    <li><a href="/common/XmlHelper/">XmlHelper</a></li>
                    <li><a href="/common/WebUtils/">WebUtils</a></li>
                </ul>
                <h3>Date Handing</h3>
                <ul>
                    <li><a href="/date/intro/">Introduction</a></li>
                    <li><a href="/date/convert/">Date Converter</a></li>
                    <li><a href="/date/formatter/">Date Formatter</a></li>
                </ul>
                <h3>Reflection</h3>
                <ul>
                    <li><a href="/reflect/Methods/">Methods</a></li>
                    <li><a href="/reflect/Types/">Types</a></li>
                    <li><a href="/reflect/Clazz/">Clazz</a></li>
                </ul>

                <h3>IO</h3>
                <ul>
                    <li><a href="/io/FileHelper/">FileHelper</a></li>
                    <li><a href="/io/Resources/">Resources</a></li>
                    <li><a href="/io/StreamHelper/">DataReader/DataWriter</a></li>
                    <li><a href="/io/ZipHelper/">ZipHelper</a></li>
                </ul>

                <h3>HTTP Request</h3>
                <ul>
                    <li><a href="/http_request/Get">HTTP Request</a></li>
                    <li><a href="/http_request/advanced-usage/">Advanced Usage</a></li>
                    <li><a href="/http_request/Base/">Base</a></li>
                </ul>
    
               <h3>Cryptography</h3>
               <ul>
                <li><a href="/cryptography/intro/">Introduction</a></li>
                <li><a href="/cryptography/flow/">Basic Flow</a></li>
                <li><a href="/cryptography/AesCrypto/">AES/DES</a></li>
                <li><a href="/cryptography/RsaCrypto/">RSA</a></li>
               </ul>
            </menu>
            <article class="aj-text">
                <h1>ObjectHelper Tutorial</h1>
<p><code>ObjectHelper</code> is an object utility class that provides common utility methods for working with Java objects, collections, maps, and various data structures.</p>
<h3>Main Features</h3>
<ol>
<li><strong>Text content checking and validation</strong></li>
<li><strong>Collection and array emptiness checks</strong></li>
<li><strong>Convenient factory methods for creating collections (maps, lists, sets)</strong></li>
<li><strong>Capacity calculation utilities</strong></li>
</ol>
<h3>Text Checking Methods</h3>
<h4>1. hasText Method</h4>
<p>Checks if the given string has actual text content:</p>
<pre><code class="language-java">// Check if string has non-whitespace content
boolean result1 = ObjectHelper.hasText(&quot;Hello&quot;);     // true
boolean result2 = ObjectHelper.hasText(&quot;   &quot;);       // false
boolean result3 = ObjectHelper.hasText(&quot;&quot;);          // false
boolean result4 = ObjectHelper.hasText(null);        // false
</code></pre>
<h4>2. isEmptyText Method</h4>
<p>Checks if the given string is empty or contains only whitespace:</p>
<pre><code class="language-java">// Check if string is empty or contains only whitespace
boolean result1 = ObjectHelper.isEmptyText(&quot;Hello&quot;); // false
boolean result2 = ObjectHelper.isEmptyText(&quot;   &quot;);   // true
boolean result3 = ObjectHelper.isEmptyText(&quot;&quot;);      // true
boolean result4 = ObjectHelper.isEmptyText(null);    // true
</code></pre>
<h3>Emptiness Checking Methods</h3>
<h4>1. Array Emptiness Check</h4>
<pre><code class="language-java">// Check if array is empty
String[] array1 = null;
String[] array2 = new String[0];
String[] array3 = {&quot;Hello&quot;};

boolean result1 = ObjectHelper.isEmpty(array1); // true
boolean result2 = ObjectHelper.isEmpty(array2); // true
boolean result3 = ObjectHelper.isEmpty(array3); // false
</code></pre>
<h4>2. Collection Emptiness Check</h4>
<pre><code class="language-java">// Check if collection is empty
List&lt;String&gt; list1 = null;
List&lt;String&gt; list2 = new ArrayList&lt;&gt;();
List&lt;String&gt; list3 = Arrays.asList(&quot;Hello&quot;);

boolean result1 = ObjectHelper.isEmpty(list1); // true
boolean result2 = ObjectHelper.isEmpty(list2); // true
boolean result3 = ObjectHelper.isEmpty(list3); // false
</code></pre>
<h4>3. Map Emptiness Check</h4>
<pre><code class="language-java">// Check if map is empty
Map&lt;String, String&gt; map1 = null;
Map&lt;String, String&gt; map2 = new HashMap&lt;&gt;();
Map&lt;String, String&gt; map3 = new HashMap&lt;&gt;();
map3.put(&quot;key&quot;, &quot;value&quot;);

boolean result1 = ObjectHelper.isEmpty(map1); // true
boolean result2 = ObjectHelper.isEmpty(map2); // true
boolean result3 = ObjectHelper.isEmpty(map3); // false
</code></pre>
<h3>Collection Creation Methods</h3>
<h4>1. Creating Maps</h4>
<pre><code class="language-java">// Create single key-value pair map
Map&lt;String, String&gt; map1 = ObjectHelper.mapOf(&quot;key1&quot;, &quot;value1&quot;);

// Create double key-value pair map
Map&lt;String, String&gt; map2 = ObjectHelper.mapOf(&quot;key1&quot;, &quot;value1&quot;, &quot;key2&quot;, &quot;value2&quot;);

// Create triple key-value pair map
Map&lt;String, String&gt; map3 = ObjectHelper.mapOf(&quot;key1&quot;, &quot;value1&quot;, &quot;key2&quot;, &quot;value2&quot;, &quot;key3&quot;, &quot;value3&quot;);

// Create map with specified capacity
Map&lt;String, String&gt; map4 = ObjectHelper.mapOf(10); // HashMap with optimized capacity
</code></pre>
<h4>2. Creating Lists</h4>
<pre><code class="language-java">// Create immutable list
List&lt;String&gt; list1 = ObjectHelper.listOf(&quot;item1&quot;);
List&lt;String&gt; list2 = ObjectHelper.listOf(&quot;item1&quot;, &quot;item2&quot;, &quot;item3&quot;);
List&lt;String&gt; list3 = ObjectHelper.listOf(); // Empty list
</code></pre>
<h4>3. Creating Sets</h4>
<pre><code class="language-java">// Create immutable set
Set&lt;String&gt; set1 = ObjectHelper.setOf(&quot;item1&quot;);
Set&lt;String&gt; set2 = ObjectHelper.setOf(&quot;item1&quot;, &quot;item2&quot;, &quot;item3&quot;);
Set&lt;String&gt; set3 = ObjectHelper.setOf(); // Empty set

// Automatic deduplication
Set&lt;String&gt; set4 = ObjectHelper.setOf(&quot;item1&quot;, &quot;item1&quot;, &quot;item2&quot;); // Contains only &quot;item1&quot; and &quot;item2&quot;
</code></pre>
<h3>Constants</h3>
<ul>
<li><code>EMPTY_PARAMS_MAP</code>: An empty, immutable map useful as a default or sentinel value when no parameters are needed</li>
<li><code>DEFAULT_LOAD_FACTOR</code>: Default load factor for hash maps, optimized for time and space efficiency</li>
</ul>
<h3>Notes</h3>
<ol>
<li><code>listOf</code> methods create immutable collections</li>
<li><code>setOf</code> method does not allow null elements</li>
<li><code>mapOf</code> methods optimize initial capacity based on expected size to minimize resizing operations</li>
</ol>

            </article>
        </div>

       <footer>
            AJ-Util, a part of <a href="https://framework.ajaxjs.com" target="_blank">AJ-Framework</a> open source. Mail:
            frank@ajaxjs.com, visit <a href="https://blog.csdn.net/zhangxin09" target="_blank">my blog(In Chinese)</a>.
            <br />
            <br />
            Copyright © 2025 Frank Cheung. All rights reserved.
        </footer>
    </body>
</html>